sha1_string_utf8


描述

在密码学中,SHA-1 是由美国 国家安全局 设计的加密散列函数,用于几种广泛使用的流行 Git 应用程序中检查文件更改。此函数将获取输入的 UTF-8 格式字符串并以 ASCII 格式返回 160 位消息摘要,例如:

sha1 input string = "The quick brown fox jumps over the lazy dog"
sha1 output hash = "2fd4e1c6 7a2d28fc ed849ee1 bb76e739 1b93eb12"


In this way you can generate a secure key which can be stored and used to check the integrity of the information being sent to (or received from) an external server (for example).

NOTE: There are two formats for the sha1 encoding, UTF-8 and unicode. Both are provided to facilitate communication with different server setups, but the most common to use is unicode.


语法:

sha1_string_utf8(string)


参数 描述
string 用于生成 MD5 散列的字符串。


返回:

String(字符串)


例如:

var hash, str;
str = json_encode(hiscore_map);
hash = sha1_string_utf8(str);
ini_open("local.ini");
ini_write_string("info", "0", hash);
ini_close();
get[0] = http_post_string("http://www.MacSweeney Games.com/CatchTheHaggis?game_hiscores=" + string(global.game_id), str)

上面的代码将 ds_map 编码为 JSON 字符串。然后生成 sha1 散列并将其存储在 ini 文件中,以便稍后可以使用它来检查 JSON 的完整性,如果稍后从服务器接收到相同的信息,JSON 就会被发送。